% reference

(de linkify (src &optional text)
  (let ((link (dom-create "a")))
    (dom-set-attribute link "href" src)
    (dom-append link (or text src))
    link))

(de make-toc-entry (topic)
  (let ((topicstr (to-string topic)))
    (linkify (string-concat "#" topicstr)
             (string-concat topicstr "<br>"))))

(de make-content (topic)
  (let ((topicstr (to-string topic))
        (element (dom-create "a")))
    (dom-set-attribute element "name" topicstr) % TODO: (implement and) use let*
    (dom-append element topicstr
      "<br>"
      (arg-info topic)
      "<br><br>"
      (car (help topic))
      "<hr>")
    element))

(let ((body (dom-get-body))
      (toc (dom-create "div"))
      (content (dom-create "div"))
      (topics (id-sort (help))))
  (dom-set-title "substandard-lisp builtin reference")
  (apply #'dom-append (cons toc (mapcar topics #'make-toc-entry)))
  (apply #'dom-append (cons content (mapcar topics #'make-content)))
  (dom-append body
    "substandard lisp currently has " (length topics) " builtins."
    "the following is an alphabetical list and the help text for each:"
    toc "<br>" content))
